import {
  hrJobAdd,
  hrResumeStatusUpdate,
  hrRectiveResumeList,
  chatList,
  companyUpdate,
} from './index';
import {
  JobInteractionListParams,
  commonJobInteractionList
} from './common';


export interface hrJobAddParams {
  position_id: number;
  name: string; //职位名称
  nature: string; //职位性质-全职、实习
  qualifications: string;  //多选学历数组
  recruit_num: number;   //招聘人数
  majors_content: string;  //专业ID数组
  salary_min: number;  //薪资下限
  salary_max: number;  //薪资上限
  salary_count: number;  //薪资期望
  highlights: string;  //职位亮点
  job_time: string;  //工作时间
  province_id: number;
  city_id: number;
  adress_detail: string;  //详细地址
  job_content: string;  //职位描述
  job_requirements: string;  //职位要求
  adress_email: string;  //简历接收邮箱
}
/**
 * HR-职位发布
 * @param {JobOrInSchoolParams} params
 * @param {string} fromContent
 * @return {number} 0 或 id值
 */
export async function HRJobAdd(params:hrJobAddParams, fromContent: string="未知"): Promise<boolean> {
  try{
    let r = await hrJobAdd(params);
    console.log(fromContent, ' HR-职位发布结果 r:::', r);
    //vue3传递result的值到子组件JobList中的属性jobList中
    if (!r) {
      console.log(fromContent,'HR-职位发布 返回值为空')
      return false;
    }
    return true;
  }catch(e){
    //TODO handle the exception
    console.log(fromContent, ' HR-职位发布异常 err:::', e)
    return false;
  }
}

/**
 * status: {number}
  1: '待处理',
  2: '已联系',
  3: '不合适',
  4: '通过初筛',
  5: '通过初试',
  6: '通过复试',
  7: '通过终试',
  8: '已签约'
*/
export interface HRResumeStatusUpdateParams {
  job_resume_id: number;
  status: number;
}
export async function HRJobResumeUpdate(params:HRResumeStatusUpdateParams, fromContent: string="未知"): Promise<number> {
  try{
    let r = await hrResumeStatusUpdate(params)
    console.log(fromContent, '更新投递简历状态 res:::', r);
    if (!r || !r.id) {
      return 0
    }
    return r.id
  }catch(e){
    //TODO handle the exception
    console.log(fromContent, '更新投递简历状态 异常:::', e);
    return 0
  }
}

export interface HRJobResumeListParams {
  status?: number | string;
  position_id?: number | string;
  start_time?: string;
  end_time?: string;
  page_no?:number;
  page_size?:number;
}
export interface HRJobResumeListResult {
  job_resume_id: number;
  resume_id: number;
  avatar: string;
  name: string;
  gender: string;
  status_name: string;
  status: number;
  province: string;
  city: string;
  qualification: string;
  nature: string;
  highlights: Array<string>;
  school_name: string;
  college_name: string;
  majors_name: string;
  status_overseas_study: string;
  heart_content: string;
  have_teacher: number;
  teacher_name: string;
  teacher_school_name: string;
  teacher_college_name: string;
}
export async function HRJobResumeList(params:HRJobResumeListParams, fromContent: string="未知"):Promise<HRJobResumeListResult[]> {
  let resultObj:HRJobResumeListResult[] = []
  try{
    let result = await hrRectiveResumeList(params);
    console.log(fromContent, ' HR-投递简历列表 结果 r::', result);
    //vue3传递result的值到子组件JobList中的属性jobList中
    for (let i = 0; i < result.list.length; i++) {
      const r = result.list[i]
      let rr:HRJobResumeListResult = {
        job_resume_id: r.id,
        resume_id: r.resume.id,
        avatar: r.user.avatar,
        name: r.user.name,
        gender: r.user.gender,
        status_name: '',
        status: r.status,
        province: r.user.province.name,
        city: r.user.city.name,
        qualification: r.user.education_last.qualification,
        nature: r.resume.intention.nature,
        highlights: r.resume.highlights,
        school_name: r.user.education_last.school_name,
        college_name: r.user.education_last.college_name,
        majors_name: r.user.education_last.majors_name,
        status_overseas_study: '',
        heart_content: r.resume.heart_content,
        have_teacher: !!r.teacher_user ? 1 : 0,
        teacher_name: '',
        teacher_school_name: '',
        teacher_college_name: '',
      }
      //1待处理 2已联系 3不合适 4通过初筛 5通过初试 6通过复试 7通过终试 8已签约
      switch (r.status){
        case 1:
          rr.status_name = '待处理'
          break;
        case 2:
          rr.status_name = '已联系'
          break;
        case 3:
          rr.status_name = '不合适'
          break;
        case 4:
          rr.status_name = '通过初筛'
          break;
        case 5:
          rr.status_name = '通过初试'
          break;
        case 6:
          rr.status_name = '通过复试'
          break;
        case 7:
          rr.status_name = '通过终试'
          break;
        case 8:
          rr.status_name = '已签约'
          break;
        default:
          break;
      }
      if (r.user.education_last.status_overseas_study == 1) {
        rr.status_overseas_study = '留学'
      } else {
        rr.status_overseas_study = '未留学'
      }
      if (rr.have_teacher == 1) {
        rr.teacher_name = r.teacher_user.name
        rr.teacher_school_name = r.teacher_user.teacher.school.name
        rr.teacher_college_name = r.teacher_user.teacher.college.name
      }
      resultObj.push(rr)
    }
    console.log(fromContent, ' HR-投递简历列表 转义结果', resultObj);
    return resultObj;
  }catch(e){
    //TODO handle the exception

    return resultObj;
  }
}

export interface HRTalkNewReturn {
  user_id: number;
  resume_send: number;
  name: string;
  avatar: string;
  detail_content: string;
}
export async function hrTalkNew(fromContent: string="HR新消息 "):Promise<HRTalkNewReturn[]> {
  let resultObj:HRTalkNewReturn[] = []
  try{
    let params:JobInteractionListParams = {
      talk_hr: 2,
      talk: 1
    }
    let r = await chatList(params)
    console.log(fromContent, 'HR聊天列表list 结果:::', r)
    if (!r.list) {
      return resultObj;
    }
    r.list.forEach(item => {
       let rr:HRTalkNewReturn = {
         user_id: item.hr_user_id,
         resume_send: item.resume_send,
         name: item.user.name,
         avatar: item.user.avatar,
         detail_content: '未知'
       }
       if (!!item.resume && !!item.resume.intention && item.resume.intention.position && item.resume.intention.position.content) {
         rr.detail_content = item.resume.intention.position.content
       }
       resultObj.push(rr)
    })
    console.log(fromContent, 'HR聊天列表list 转义结果', resultObj);
    return resultObj;
  }catch(e){
    //TODO handle the exception
    console.log(fromContent, 'HR聊天列表异常 err:::', e)
    return resultObj;
  }
}

export async function hrTalkING(fromContent: string="HR沟通中"):Promise<HRTalkNewReturn[]> {
  let resultObj:HRTalkNewReturn[] = []
  try{
    let params:JobInteractionListParams = {
      talk_hr: 1
    }
    let r = await chatList(params)
    console.log(fromContent, 'HR聊天列表list 结果:::', r)
    if (!r.list) {
      return resultObj;
    }
    r.list.forEach(item => {
       let rr:HRTalkNewReturn = {
         user_id: item.hr_user_id,
         resume_send: item.resume_send,
         name: item.user.name,
         avatar: item.user.avatar,
         detail_content: '未知'
       }
       if (!!item.resume && !!item.resume.intention && item.resume.intention.position && item.resume.intention.position.content) {
         rr.detail_content = item.resume.intention.position.content
       }
       resultObj.push(rr)
    })
    console.log(fromContent, 'HR聊天列表list 转义结果', resultObj);
    return resultObj;
  }catch(e){
    //TODO handle the exception
    console.log(fromContent, '聊天列表异常 err:::', e)
    return resultObj;
  }
}

export async function hrTalkLike(fromContent: string="HR感兴趣"):Promise<HRTalkNewReturn[]> {
  let resultObj:HRTalkNewReturn[] = []
  try{
    let params:JobInteractionListParams = {
      like_hr: 1
    }
    let r = await chatList(params)
    console.log(fromContent, 'HR聊天列表list 结果:::', r)
    if (!r.list) {
      return resultObj;
    }
    r.list.forEach(item => {
       let rr:HRTalkNewReturn = {
         user_id: item.hr_user_id,
         resume_send: item.resume_send,
         name: item.user.name,
         avatar: item.user.avatar,
         detail_content: '未知'
       }
       if (!!item.resume && !!item.resume.intention && item.resume.intention.position && item.resume.intention.position.content) {
         rr.detail_content = item.resume.intention.position.content
       }
       resultObj.push(rr)
    })
    console.log(fromContent, 'HR聊天列表list 转义结果', resultObj);
    return resultObj;
  }catch(e){
    //TODO handle the exception
    console.log(fromContent, '聊天列表异常 err:::', e)
    return resultObj;
  }
}

export interface CompanyInfoUpdateParams {
  /*
  更新参数、类型、描述 对照数据
  `name`'企业名称',
  `url_logo` '企业logo地址',
  `about_us` text '公司简介 富文本',
  `adress` text '公司地址',
  `type` 数字-公司类型 1民营 2国企', `
  listed` 数字-上市状态 1未上市 2上市',
  `num` 字符串-'公司人数',
  `province_id` '省',
  `job_count` int '招聘职位数',
  `job_num` int '招聘人数',
  `official_website` varchar(200) '招聘官网',
  `image` json DEFAULT NULL COMMENT '企业介绍图片',
  `image_detail` json DEFAULT NULL COMMENT '企业风光',
  `born_year` int NOT NULL DEFAULT '0' COMMENT '成立年份',
  `born_money` varchar(200) '成立资本',
  `label_statutory_benefits` json '法定福利 多选json数组 例：[五险,一金...]',
  `label_bonus` json '奖金类 多选json数组 例：[年终奖,绩效奖...]',
  `label_medical_care` json DEFAULT NULL COMMENT '标签-医 多选json数组 例：[...]',
  `label_food` json DEFAULT NULL COMMENT '标签-食 多选json数组 例：[...]',
  `label_live` json DEFAULT NULL COMMENT '标签-住 多选json数组 例：[...]',
  `label_go` json DEFAULT NULL COMMENT '标签-行 多选json数组 例：[...]',
  `label_entertainment` json DEFAULT NULL COMMENT '标签-娱 多选json数组 例：[...]',
  `label_supplement` json DEFAULT NULL COMMENT '标签-补充 多选json数组 例：[...]',
  `label_grow_up` json DEFAULT NULL COMMENT '标签-学习/成长 多选json数组 例：[...]',
  `label_custom` json DEFAULT NULL COMMENT '标签-自定义 多选json数组 例：[...]',
  `subsidy_job` text '补贴-基层就业',
  `subsidy_rent_house` text '补贴-住房',
  `subsidy_interview` text '补贴-面试',
  `subsidy_buy_house` text '补贴-人才购房',
  `subsidy_traffic` text '补贴-交通',
  `subsidy_life` text '补贴-人才引进生活补贴',
  `subsidy_return_home` text '补贴-大学生返乡安家',
  `subsidy_other` text '补贴-其他',
  `personnel_training` text '人才培养',
  `honor` json DEFAULT NULL COMMENT '公司荣誉 json数组',
  `seniors_say` varchar(200) '师哥师姐说(视频地址)',
  */
  //公司简介
  company_id: number;
  name?: string;
  url_logo?: string;
  about_us?: string;
  adress?: string;
  type?: number;
  listed?: number;
  num?: string;
  province_id?: number;
  city_id?: number;
  job_count?: number;
  job_num?: number;
  official_website?: string;
  image?: string;
  image_detail?: string;
  born_year?: number;
  born_money?: string;
  //校招亮点
  label_statutory_benefits?: string;
  label_bonus?: string;
  label_medical_care?: string;
  label_food?: string;
  label_live?: string;
  label_go?: string;
  label_entertainment?: string;
  label_supplement?: string;
  label_grow_up?: string;
  label_custom?: string;
  subsidy_job?: string;
  subsidy_rent_house?: string;
  subsidy_interview?: string;
  subsidy_buy_house?: string;
  subsidy_traffic?: string;
  subsidy_life?: string;
  subsidy_return_home?: string;
  subsidy_other?: string;
  personnel_training?: string;
  honor?: string;
  seniors_say?: string;
}
/**
 * HR-更新公司信息
 * @param {JobOrInSchoolParams} params
 * @param {string} fromContent
 * @return {number} 0 或 id值
 */
export async function companyInfoUpdate(params:CompanyInfoUpdateParams, fromContent: string="未知"): Promise<number> {
  try{
    console.log(fromContent, ' HR-更新用户信息 参数 r:::', params);
    let r = await companyUpdate(params);
    console.log(fromContent, ' HR-更新用户信息 结果 r:::', r);
    //vue3传递result的值到子组件JobList中的属性jobList中
    if (!r || !r.id) {
      console.log(fromContent,'HR-更新用户信息 返回值为空')
      return 0;
    }
    return r.id;
  }catch(e){
    //TODO handle the exception
    console.log(fromContent, ' HR-更新用户信息 err:::', e)
    return 0;
  }
}
